package self.security.utils;

import com.alibaba.fastjson.JSON;
import self.result.R;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 作者: liYU
 * 项目名称: WX_Self_Iot_parent
 * 标题: HttpResponseUtils
 * 该类描述: HttpResponse响应的工具类
 * 创建日期: 2025/4/15 16:19
 */
public class HttpResponseUtils {

    public static void sendResponse(HttpServletResponse resp, R r) {
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter writer = null;
        try {
            writer = resp.getWriter();
            writer.write(JSON.toJSONString(r));
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            writer.flush();
            writer.close();
        }
    }

}
